package com.STS.ELearning.Classes
{
	import flash.display.Loader;
	import flash.events.Event;
	import flash.events.IOErrorEvent;
	import flash.events.ProgressEvent;
	import flash.events.SecurityErrorEvent;
	import flash.filesystem.*;
	import flash.net.URLLoader;
	import flash.net.URLRequest;
	import flash.net.URLStream;
	import flash.net.URLVariables;
	import flash.system.ApplicationDomain;
	import flash.system.LoaderContext;
	import flash.system.Security;
	import flash.system.SecurityDomain;
	import flash.system.System;
	import flash.utils.ByteArray;
	import flash.utils.describeType;
	import flash.utils.flash_proxy;
	import flash.xml.*;
	
	import mx.controls.Alert;
	import mx.controls.SWFLoader;
	import mx.core.Application;
	import mx.events.CloseEvent;
	import mx.managers.SystemManager;
	import mx.messaging.events.MessageEvent;
	import mx.utils.StringUtil;
	import mx.utils.URLUtil;
	
	import org.osmf.utils.URL;
	
	public class Helper extends Base
	{
		
			
		public static function getSure(milisan:int):Object
		{
			var retObj:Object=new Object();
			retObj.topsn=int(milisan/1000);
			retObj.saat=int(retObj.topsn/360);
			retObj.dkk=int((retObj.topsn-(retObj.saat*360))/60);
			retObj.snn=int(retObj.topsn-(retObj.saat*360)-(retObj.dkk*60));
			return retObj;
		}
		public static function trim( s:String ):String
		{
			
			return StringUtil.trim(s);
			return s.replace( /^([\s|\t|\n]+)?(.*)([\s|\t|\n]+)?$/gm, "$2" );
		}
		public static function xmlEncode(s:Object):String
		{
			var r:String=s.toString();
			r=r.replace("\"","&quot;");
			r=r.replace("<","&lt;");
			r=r.replace(">","&gt;");
			r=r.replace("&","&amp;");
			r=r.replace("'","&#39;");
			return r;
		}
		public function Helper()
		{
			
		}
		
		public function getFileStream(fileName:String):FileStream
		{
			// File reference
			var file:File;
			file = File.applicationDirectory.resolvePath(fileName);
			if(!file.exists)
			{
				throw "Dosya Bulunamadı.("+fileName+")";
			}
			var fileStream:FileStream = new FileStream();
			fileStream.open(file, FileMode.READ);
			return fileStream;
		}
		
		public function LoadFileBytes(fileName:String):ByteArray
		{
			
			var fileStream:FileStream=getFileStream(fileName);	
			// Read SWF bytes into byte array and close file
			var bytes: ByteArray = new ByteArray();
			fileStream.readBytes(bytes);
			fileStream.close();
			return bytes;
		}
		public function loadXml(fileName:String):XML
		{
			var fs:FileStream=getFileStream(fileName);
			if(fs.bytesAvailable)
			{
				var str:String=fs.readUTFBytes(File.applicationDirectory.resolvePath(fileName).size);
				var xm:XML=new XML(str);
			}
			fs.close();
			return xm;
		}
		public function loadLocalSwf(ldr:SWFLoader,fileName:String):void
		{
			
			var f:File=File.applicationDirectory.resolvePath(fileName);
			f=File.applicationDirectory.resolvePath(f.url);
			
			var lc:LoaderContext=new LoaderContext(false,new ApplicationDomain(ApplicationDomain.currentDomain),null);
			lc.allowLoadBytesCodeExecution=true;
			
			ldr.autoLoad=true;
			ldr.addEventListener(ProgressEvent.PROGRESS,function(evt:ProgressEvent):void{
				trace(evt.currentTarget.content);
			});
			ldr.loaderContext=lc;
			ldr.trustContent=true;
			ldr.addEventListener(SecurityErrorEvent.SECURITY_ERROR,function (se:SecurityErrorEvent){
				
			});
			ldr.source=f.url;
			return;
				
				
			
			/*var l:Loader=new Loader();
			l.addEventListener(Event.ENTER_FRAME,function(evt:Event){
			
				var cap:*=l.content;
				trace(cap);
			});
			l.addEventListener(ProgressEvent.PROGRESS,function(evt:ProgressEvent):void{
				trace(evt.currentTarget.content);
			});
			l.addEventListener(Event.COMPLETE,function(evt:Event){
				var cap:*=evt.currentTarget.content;
				describeType(cap);
				ldr.autoLoad=true;
				ldr.addEventListener(ProgressEvent.PROGRESS,function(evt:ProgressEvent):void{
					trace(evt.currentTarget.content);
				});
				ldr.loaderContext=lc;
				ldr.trustContent=true;
				ldr.addEventListener(SecurityErrorEvent.SECURITY_ERROR,function (se:SecurityErrorEvent){
					
				});
				ldr.source =cap;	
			});
			var ur:URLRequest=new URLRequest(f.url);
			l.load(ur,lc);*/
			
						
			
			return;
		}
	}
}